import {
  addRolesRequest,
  getRolesRequest,
  deteleRolesRequest,
  editRolesRequest
} from '@/service/roles/roles.js'

export default {
  state: {
    rolesList: []
  },
  mutations: {
    changeRoles(state, roles) {
      state.rolesList = roles
    }
  },
  actions: {
    async requestRoles({ commit }) {
      const rolesRes = await getRolesRequest()
      commit('changeRoles', rolesRes)
    },
    async addRequestRoles({ dispatch, commit }, data) {
      await addRolesRequest(data)
      dispatch('requestRoles')
    },
    async deteleRequestRoles({ dispatch, commit }, rId) {
      await deteleRolesRequest({
        rId
      })
      dispatch('requestRoles')
    },
    async EditRequestRoles({ dispatch, commit }, data) {
      await editRolesRequest(data)
      dispatch('requestRoles')
    }
  }
}
